/*
 * Copyright (c) 2022，公司名称
 * All rights reserved.
 * 文件名称：low_lin.h
 * 摘要：低边LIN
 * 当前版本：V1.0.0,WCD,2023/1/10,初版
 * 历史版本：Vx.x.x，编写者/修改者，修改时间，修改内容（重大发布时，总结重点变更内容）
 */

#ifndef LOW_LIN_H
#define LOW_LIN_H

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓应用层数据定义开始↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
#if 1

#define CA_Contrl_ID (0X15U)  /*slave node reception response 从节点接收响应*/
#define Report_Value_ID (0X16U) /*slave node transmit response 从节点发送响应*/

#define LIN_TIMEOUT (4000U) /* lIN 总线消息超时 */

typedef enum
{
    RLINSTA_NORMAL = 0,
    RLINSTA_SLEEP
} RLINSTA_E;
#endif
/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑应用层数据定义结束↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/

#define SLAVE_REC_FRAME 0x01  /*slave node reception response 从节点接收响应*/
#define SLAVE_SEND_FRAME 0x33 /*slave node transmit response 从节点发送响应*/

#define TIME_OUT_UNIT_US 500U /*stim period is 500us*/
#define LIN_SLAVE_ID UART0_ID /*stim period is 500us*/

#define UART_LIN_TO_ERR (1U << 13U)
#define UART_LIN_CHECKSUM_ERR (1U << 12U)
#define UART_LIN_PID_ERR (1U << 11U)
#define UART_LIN_SYNC_FIELD_ERR (1U << 10U)
#define UART_LIN_ASYNC_INT_FLAG (1U << 9U)
#define UART_LIN_HEADER_ERR_FLAG (UART_LIN_SYNC_FIELD_ERR | \
                                  UART_LIN_PID_ERR |        \
                                  UART_LIN_TO_ERR)

#define UART_LIN_RSP_ERR_FLAG (UART_LIN_CHECKSUM_ERR | \
                               UART_LIN_TO_ERR)
typedef enum
{
  LIN_RES_NO_ERROR = 0U,        /*!< Lin respones no error lin响应没有错误*/
  LIN_RES_TIME_OUT = 1U,        /*!< Lin respones time out error lin响应超时错误*/
  LIN_RES_ID_CONFLICT = 2U,     /*!< Lin respones ID conflict lin响应ID不一致*/
  LIN_RSP_DONE_INT_ERR = 3U,    /*!< Lin checksum error or time out error Lin校验和错误或超时错误*/
  LIN_HEADER_DONE_INT_ERR = 4U, /*!< Lin sync field error , PID error or time out error Lin同步字段错误、PID错误或超时错误*/
} LIN_Res_Error_Status;

void low_lin_init();
void low_lin_clock_init(void);
void TIME_PeriodHandle(void);

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓应用层函数定义开始↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
#if 1
/* 
 * 函数介绍: 获取总线状态
 * 参数: {RLINSTA_E} sta
 * 返回值: {*}
 * 备注: 
 */
RLINSTA_E RLIN31_sta_get(void);
void lin31_main(void);
#endif
/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑应用层函数定义结束↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/
#endif
